import requests
from bs4 import BeautifulSoup


url = "https://www.baidu.com"
r = requests.get(url)

r.encoding = 'utf-8'

    # r.text待解析的源文件
    # html.parser解析器
soup = BeautifulSoup(r.text, "html.parser")

a_list = soup.find_all("a") # 获取所有a标签

for a in a_list:
    print(a.text)
    print(a.get("href"))
    # print(a.text,a.get('href'))
    # a.text获取a标签中的文字
    # href: 获取a标签的href属性
